package com.example.teachmvandroidchart.ui

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import com.android.frame.mvp.CommonBaseActivity
import com.bjw.utils.SerialHelper
import com.chad.library.adapter.base.BaseQuickAdapter
import com.example.teachmvandroidchart.R
import com.example.teachmvandroidchart.Adapter.AnimationAdapter
import com.example.teachmvandroidchart.databinding.ActivityTeachMainBinding
import com.example.teachmvandroidchart.util.Status
import com.gyf.immersionbar.ImmersionBar
import java.io.IOException
import java.util.ArrayList
import java.util.HashMap

/**
 * Created by dell on 2021/8/11.mvp
 */
class TeachingActivity: CommonBaseActivity<ActivityTeachMainBinding>() {
    private var mAnimationAdapter: AnimationAdapter? = null


    private val list = ArrayList<Map<String, Any>>()
    var map: Map<String, Any>? = null

    override fun handleView(savedInstanceState: Bundle?) {
        intView()

        Handler(Looper.getMainLooper()).postDelayed({
            /**
             * 数据初始化（200毫秒）AddDeviceActivity
             * */
            intDate()
            initAdapter()
        }, 300)

    }

    private fun intView() {
        ImmersionBar.with(this).titleBar(binding.toolbar).init()
        ImmersionBar.with(this).titleBar(binding.toolbar).keyboardEnable(true).init()
        //返回按钮
        setSupportActionBar(binding.toolbar)
        val actionBar = supportActionBar
        actionBar?.setDisplayHomeAsUpEnabled(true)
    }

    override fun initListener() {

        //toolbar返回按钮监听
        binding.toolbar.setNavigationOnClickListener { finish() }
    }
    private fun initAdapter() {

        mAnimationAdapter = AnimationAdapter(list)
        //打开动画
        mAnimationAdapter?.animationEnable ?: true
        mAnimationAdapter!!.addChildClickViewIds(R.id.headr, R.id.tweetName, R.id.list_item)
        mAnimationAdapter!!.setOnItemChildClickListener { adapter, view, position ->

            var status = adapter.getItem(position) as Status
            when (view.id) {
                R.id.headr -> showToast("请点击标题栏")
                R.id.tweetName ->
                    showToast("简介：" + list[position]["course"].toString())
                R.id.list_item ->
                when(position){
                    0 -> startActivity(PortActivity ::class.java)
                    1 -> startActivity(MPAndroidChartActivity ::class.java)
                    2 -> startActivity(SeriaPortHomeActivity ::class.java)
                    3 -> startActivity(SeriaPortHomesActivity::class.java)
                    4 -> startActivity(HistotyActivity::class.java)
                    else -> {
                    }
                }
                else -> {
                }
            }
        }
        mAnimationAdapter!!.setAnimationWithDefault(BaseQuickAdapter.AnimationType.SlideInRight)
        mRecyclerView?.adapter = mAnimationAdapter
    }
    private fun intDate(){
        val kList: List<String> = listOf(
            "课时一",
            "课时二",
            "课时三",
            "课时四",
            "课时五")
        val mList: List<String> = listOf(
           "串口通讯使用，实现显示串口消息以及发送串口消息",
            "MPAdroidchart简单使用，条状以及饼图等",
            "单个房间实现折线图监控显示",
            "多个房间实现折线图监控显示",
            "历史数据查看以及分析")
        val sList: List<String> = listOf(
            "Kotlin串口通信实现",
            "MVAdroidChart图表使用",
            "单房间温湿度图表显示功能实现",
            "多房间温湿度图表显示功能实现",
            "历史数据分析图表显示功能实现")

        for (i in 0 until 5) {
            map = HashMap()
            (map as HashMap<String, Any>)["course"] = mList[i]
            (map as HashMap<String, Any>)["id"] = kList[i]
            (map as HashMap<String, Any>)["name"] = sList[i]
            list.add(map as HashMap<String, Any>)
        }
    }

}
